# 查看字符串有哪些方法
print(help(str))
message = "hello"
print(dir(message))

# 查看某个方法的具体使用
help(str.count)
help(message.count)

# 查找字符串中1出现的次数
print(message.count('1'))
message = "adf223111ncandfd"
print(message.count('1'))
print()

# 判断类
print("判断类")
str0 = "123"
str1 = "123a"
str2 = "123一二三"
str3 = "123a一二三"

# isdigit => 字符串中是否只包含数字
print(str0.isdigit())
print(str1.isdigit())
print(str2.isdigit())
print(str3.isdigit())
print()

# isnumberic => 字符串是否只包含数字包括中文数字
print(str0.isnumeric())
print(str1.isnumeric())
print(str2.isnumeric())
print(str3.isnumeric())
print()

# isalnum
print(str0.isalnum())
print(str1.isalnum())
print(str2.isalnum())
print(str3.isalnum())
print()

# isalpha
str0 = "一二三"
str1 = "王文龙"
str2 = "wang"
str3 = "wangwenlong"
print(str0.isalpha())
print(str1.isalpha())
print(str2.isalpha())
print(str3.isalpha())
print()

# 统计类
print("统计类")
message = "a ~ z"
print(message)
print(message.__len__())
print(len(message))
print()

message = "hello hello hello hello hello"
print(message.count('hello'))
print(message.count('hello', 5))
print(message.count('hello', 5, 10))
print(message.count('hello', 5, 11))
print()

# 查找一个字串出现的下标的起始位置
print(message.index("hello"))   # 0
print(message.index(" hello"))  # 5
print(message.find("hello"))    # 0
print(message.find(" hello"))   # 5
print()

message = "hello! WORLD"
print(message.upper())
print(message.lower())
print(message.title())  # 将子串首字母小写，其它字母大写
print()

# strip => 去掉字符串左右两边的指定的字符
message = "   hello! WORLD"
print(message)
print(message.strip())
print(message.strip('   h!'))   # ello! WORLD
print()

# split => 指定切割符，默认空格
message = "root:x:1:this is root:/bin/bash"
result = message.split(':')
print(result, result[3])
# join => 指定连接符
print(":".join(result))
print()

# replace => 替换 默认替换所有
message = "hello hello hello hello hello"
print(message.replace("o", "l"))
print(message.replace("o", "l", 2))
print()

# encode 转换为字节
message = "hello"
print(message.encode(), type(message.encode()))
message = "你好"
print(message.encode(), type(message.encode()))